From 0e0f890e8931301721590745b35b8014311fd219 Mon Sep 17 00:00:00 2001 From: "kaf24@firebug.cl.cam.ac.uk" Date: Tue, 30 Aug 2005 17:53:49 +0000 Subject: [PATCH] Unify access to mpt using macros. Also some code cleanup to x86_64 fault.c Signed-off-by: Xin Li --- .../arch/xen/x86_64/mm/fault.c | 10 +++++----- xen/arch/x86/domain.c | 8 ++++---- xen/arch/x86/domain_build.c | 7 +++---- xen/arch/x86/mm.c | 6 +++--- xen/arch/x86/shadow32.c | 4 ++-- xen/arch/x86/shadow_public.c | 4 ++-- xen/arch/x86/vmx.c | 12 ++++++------ xen/arch/x86/vmx_platform.c | 6 +++--- xen/arch/x86/vmx_vmcs.c | 4 ++-- xen/common/grant_table.c | 7 +++---- xen/include/asm-ia64/mm.h | 4 ++-- xen/include/asm-x86/mm.h | 18 ++++++++++-------- xen/include/asm-x86/shadow.h | 8 ++++---- xen/include/asm-x86/shadow_64.h | 6 +++--- xen/include/asm-x86/vmx_platform.h | 2 +- 15 files changed, 53 insertions(+), 53 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c index c0c5dc86b5..3a4db31d4d 100644 --- a/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c +++ b/linux-2.6-xen-sparse/arch/xen/x86_64/mm/fault.c @@ -149,7 +149,7 @@ void dump_pagetable(unsigned long address) pmd_t *pmd; pte_t *pte; - pgd = (pgd_t *)per_cpu(cur_pgd, smp_processor_id()); + pgd = (pgd_t *)per_cpu(cur_pgd, smp_processor_id()); pgd += pgd_index(address); printk("PGD %lx ", pgd_val(*pgd)); @@ -296,9 +296,9 @@ int exception_trace = 1; #define MEM_VERBOSE 1 #ifdef MEM_VERBOSE -#define MEM_LOG(_f, _a...) \ - printk("fault.c:[%d]-> " _f "\n", \ - __LINE__ , ## _a ) +#define MEM_LOG(_f, _a...) \ + printk("fault.c:[%d]-> " _f "\n", \ + __LINE__ , ## _a ) #else #define MEM_LOG(_f, _a...) ((void)0) #endif @@ -325,7 +325,7 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long error_code, siginfo_t info; if (!user_mode(regs)) - error_code &= ~4; /* means kernel */ + error_code &= ~4; /* means kernel */ #ifdef CONFIG_CHECKING { diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 974ec0c2dc..7a15059416 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -255,13 +255,13 @@ void arch_do_createdomain(struct vcpu *v) v->vcpu_info = &d->shared_info->vcpu_data[v->vcpu_id]; v->cpumap = CPUMAP_RUNANYWHERE; SHARE_PFN_WITH_DOMAIN(virt_to_page(d->shared_info), d); - machine_to_phys_mapping[virt_to_phys(d->shared_info) >> - PAGE_SHIFT] = INVALID_M2P_ENTRY; + set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, + INVALID_M2P_ENTRY); d->arch.mm_perdomain_pt = alloc_xenheap_page(); memset(d->arch.mm_perdomain_pt, 0, PAGE_SIZE); - machine_to_phys_mapping[virt_to_phys(d->arch.mm_perdomain_pt) >> - PAGE_SHIFT] = INVALID_M2P_ENTRY; + set_pfn_from_mfn(virt_to_phys(d->arch.mm_perdomain_pt) >> PAGE_SHIFT, + INVALID_M2P_ENTRY); v->arch.perdomain_ptes = d->arch.mm_perdomain_pt; v->arch.perdomain_ptes[FIRST_RESERVED_GDT_PAGE] = l1e_from_page(virt_to_page(gdt_table), PAGE_HYPERVISOR); diff --git a/xen/arch/x86/domain_build.c b/xen/arch/x86/domain_build.c index 1b77371141..8b64b0ee45 100644 --- a/xen/arch/x86/domain_build.c +++ b/xen/arch/x86/domain_build.c @@ -592,8 +592,7 @@ int construct_dom0(struct domain *d, if ( opt_dom0_translate ) { si->shared_info = d->next_io_page << PAGE_SHIFT; - set_machinetophys(virt_to_phys(d->shared_info) >> PAGE_SHIFT, - d->next_io_page); + set_pfn_from_mfn(virt_to_phys(d->shared_info) >> PAGE_SHIFT, d->next_io_page); d->next_io_page++; } else @@ -614,7 +613,7 @@ int construct_dom0(struct domain *d, mfn = alloc_epfn - (pfn - REVERSE_START); #endif ((u32 *)vphysmap_start)[pfn] = mfn; - machine_to_phys_mapping[mfn] = pfn; + set_pfn_from_mfn(mfn, pfn); } while ( pfn < nr_pages ) { @@ -627,7 +626,7 @@ int construct_dom0(struct domain *d, #define pfn (nr_pages - 1 - (pfn - (alloc_epfn - alloc_spfn))) #endif ((u32 *)vphysmap_start)[pfn] = mfn; - machine_to_phys_mapping[mfn] = pfn; + set_pfn_from_mfn(mfn, pfn); #undef pfn page++; pfn++; } diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 0141937ad2..119906b132 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1452,7 +1452,7 @@ int get_page_type(struct pfn_info *page, unsigned long type) "!= exp %" PRtype_info ") " "for mfn %lx (pfn %x)", x, type, page_to_pfn(page), - machine_to_phys_mapping[page_to_pfn(page)]); + get_pfn_from_mfn(page_to_pfn(page))); return 0; } else if ( (x & PGT_va_mask) == PGT_va_mutable ) @@ -2206,7 +2206,7 @@ int do_mmu_update( printk("privileged guest dom%d requests pfn=%lx to " "map mfn=%lx for dom%d\n", d->domain_id, gpfn, mfn, FOREIGNDOM->domain_id); - set_machinetophys(mfn, gpfn); + set_pfn_from_mfn(mfn, gpfn); set_p2m_entry(FOREIGNDOM, gpfn, mfn, &sh_mapcache, &mapcache); okay = 1; shadow_unlock(FOREIGNDOM); @@ -2225,7 +2225,7 @@ int do_mmu_update( break; } - set_machinetophys(mfn, gpfn); + set_pfn_from_mfn(mfn, gpfn); okay = 1; /* diff --git a/xen/arch/x86/shadow32.c b/xen/arch/x86/shadow32.c index 8f7414a8a7..8b88049f78 100644 --- a/xen/arch/x86/shadow32.c +++ b/xen/arch/x86/shadow32.c @@ -827,7 +827,7 @@ alloc_p2m_table(struct domain *d) { page = list_entry(list_ent, struct pfn_info, list); mfn = page_to_pfn(page); - pfn = machine_to_phys_mapping[mfn]; + pfn = get_pfn_from_mfn(mfn); ASSERT(pfn != INVALID_M2P_ENTRY); ASSERT(pfn < (1u<<20)); @@ -841,7 +841,7 @@ alloc_p2m_table(struct domain *d) { page = list_entry(list_ent, struct pfn_info, list); mfn = page_to_pfn(page); - pfn = machine_to_phys_mapping[mfn]; + pfn = get_pfn_from_mfn(mfn); if ( (pfn != INVALID_M2P_ENTRY) && (pfn < (1u<<20)) ) { diff --git a/xen/arch/x86/shadow_public.c b/xen/arch/x86/shadow_public.c index 88cd5fcd51..d554b4f538 100644 --- a/xen/arch/x86/shadow_public.c +++ b/xen/arch/x86/shadow_public.c @@ -1311,7 +1311,7 @@ alloc_p2m_table(struct domain *d) { page = list_entry(list_ent, struct pfn_info, list); mfn = page_to_pfn(page); - pfn = machine_to_phys_mapping[mfn]; + pfn = get_pfn_from_mfn(mfn); ASSERT(pfn != INVALID_M2P_ENTRY); ASSERT(pfn < (1u<<20)); @@ -1325,7 +1325,7 @@ alloc_p2m_table(struct domain *d) { page = list_entry(list_ent, struct pfn_info, list); mfn = page_to_pfn(page); - pfn = machine_to_phys_mapping[mfn]; + pfn = get_pfn_from_mfn(mfn); if ( (pfn != INVALID_M2P_ENTRY) && (pfn < (1u<<20)) ) { diff --git a/xen/arch/x86/vmx.c b/xen/arch/x86/vmx.c index d9725938e0..5b95f043db 100644 --- a/xen/arch/x86/vmx.c +++ b/xen/arch/x86/vmx.c @@ -694,7 +694,7 @@ vmx_copy(void *buf, unsigned long laddr, int size, int dir) return 0; } - mfn = phys_to_machine_mapping(laddr >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(laddr >> PAGE_SHIFT); addr = (char *)map_domain_page(mfn) + (laddr & ~PAGE_MASK); if (dir == COPY_IN) @@ -795,7 +795,7 @@ vmx_world_restore(struct vcpu *d, struct vmx_assist_context *c) * removed some translation or changed page attributes. * We simply invalidate the shadow. */ - mfn = phys_to_machine_mapping(c->cr3 >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(c->cr3 >> PAGE_SHIFT); if (mfn != pagetable_get_pfn(d->arch.guest_table)) { printk("Invalid CR3 value=%x", c->cr3); domain_crash_synchronous(); @@ -813,7 +813,7 @@ vmx_world_restore(struct vcpu *d, struct vmx_assist_context *c) domain_crash_synchronous(); return 0; } - mfn = phys_to_machine_mapping(c->cr3 >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(c->cr3 >> PAGE_SHIFT); d->arch.guest_table = mk_pagetable(mfn << PAGE_SHIFT); update_pagetables(d); /* @@ -968,7 +968,7 @@ static int vmx_set_cr0(unsigned long value) /* * The guest CR3 must be pointing to the guest physical. */ - if ( !VALID_MFN(mfn = phys_to_machine_mapping( + if ( !VALID_MFN(mfn = get_mfn_from_pfn( d->arch.arch_vmx.cpu_cr3 >> PAGE_SHIFT)) || !get_page(pfn_to_page(mfn), d->domain) ) { @@ -1164,7 +1164,7 @@ static int mov_to_cr(int gp, int cr, struct cpu_user_regs *regs) * removed some translation or changed page attributes. * We simply invalidate the shadow. */ - mfn = phys_to_machine_mapping(value >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(value >> PAGE_SHIFT); if (mfn != pagetable_get_pfn(d->arch.guest_table)) __vmx_bug(regs); shadow_sync_all(d->domain); @@ -1175,7 +1175,7 @@ static int mov_to_cr(int gp, int cr, struct cpu_user_regs *regs) */ VMX_DBG_LOG(DBG_LEVEL_VMMU, "CR3 value = %lx", value); if ( ((value >> PAGE_SHIFT) > d->domain->max_pages ) || - !VALID_MFN(mfn = phys_to_machine_mapping(value >> PAGE_SHIFT)) || + !VALID_MFN(mfn = get_mfn_from_pfn(value >> PAGE_SHIFT)) || !get_page(pfn_to_page(mfn), d->domain) ) { printk("Invalid CR3 value=%lx", value); diff --git a/xen/arch/x86/vmx_platform.c b/xen/arch/x86/vmx_platform.c index 34b7d8e6f8..220c9b05b4 100644 --- a/xen/arch/x86/vmx_platform.c +++ b/xen/arch/x86/vmx_platform.c @@ -521,7 +521,7 @@ int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int inst_l if ( vmx_paging_enabled(current) ) { gpa = gva_to_gpa(guest_eip); - mfn = phys_to_machine_mapping(gpa >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT); /* Does this cross a page boundary ? */ if ( (guest_eip & PAGE_MASK) != ((guest_eip + inst_len) & PAGE_MASK) ) @@ -532,7 +532,7 @@ int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int inst_l } else { - mfn = phys_to_machine_mapping(guest_eip >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(guest_eip >> PAGE_SHIFT); } inst_start = map_domain_page(mfn); @@ -542,7 +542,7 @@ int inst_copy_from_guest(unsigned char *buf, unsigned long guest_eip, int inst_l if ( remaining ) { gpa = gva_to_gpa(guest_eip+inst_len+remaining); - mfn = phys_to_machine_mapping(gpa >> PAGE_SHIFT); + mfn = get_mfn_from_pfn(gpa >> PAGE_SHIFT); inst_start = map_domain_page(mfn); memcpy((char *)buf+inst_len, inst_start, remaining); diff --git a/xen/arch/x86/vmx_vmcs.c b/xen/arch/x86/vmx_vmcs.c index c83df67ddf..8a2402fd9a 100644 --- a/xen/arch/x86/vmx_vmcs.c +++ b/xen/arch/x86/vmx_vmcs.c @@ -148,7 +148,7 @@ int vmx_setup_platform(struct vcpu *d, struct cpu_user_regs *regs) offset = (addr & ~PAGE_MASK); addr = round_pgdown(addr); - mpfn = phys_to_machine_mapping(addr >> PAGE_SHIFT); + mpfn = get_mfn_from_pfn(addr >> PAGE_SHIFT); p = map_domain_page(mpfn); e820p = (struct e820entry *) ((unsigned long) p + offset); @@ -175,7 +175,7 @@ int vmx_setup_platform(struct vcpu *d, struct cpu_user_regs *regs) unmap_domain_page(p); /* Initialise shared page */ - mpfn = phys_to_machine_mapping(gpfn); + mpfn = get_mfn_from_pfn(gpfn); p = map_domain_page(mpfn); d->domain->arch.vmx_platform.shared_page_va = (unsigned long)p; diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 7ff75aab4d..7f3c5b4a62 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1211,13 +1211,13 @@ gnttab_notify_transfer( DPRINTK("Bad pfn (%lx)\n", pfn); else { - machine_to_phys_mapping[frame] = pfn; + set_pfn_from_mfn(frame, pfn); if ( unlikely(shadow_mode_log_dirty(ld))) mark_dirty(ld, frame); if (shadow_mode_translate(ld)) - __phys_to_machine_mapping[pfn] = frame; + set_mfn_from_pfn(pfn, frame); } sha->frame = __mfn_to_gpfn(rd, frame); sha->domid = rd->domain_id; @@ -1268,8 +1268,7 @@ grant_table_create( { SHARE_PFN_WITH_DOMAIN( virt_to_page((char *)(t->shared)+(i*PAGE_SIZE)), d); - machine_to_phys_mapping[(virt_to_phys(t->shared) >> PAGE_SHIFT) + i] = - INVALID_M2P_ENTRY; + set_pfn_from_mfn((virt_to_phys(t->shared) >> PAGE_SHIFT) + i, INVALID_M2P_ENTRY); } /* Okay, install the structure. */ diff --git a/xen/include/asm-ia64/mm.h b/xen/include/asm-ia64/mm.h index 1bb283873d..4ca4e49513 100644 --- a/xen/include/asm-ia64/mm.h +++ b/xen/include/asm-ia64/mm.h @@ -405,7 +405,7 @@ extern unsigned long *mpt_table; /* If pmt table is provided by control pannel later, we need __get_user * here. However if it's allocated by HV, we should access it directly */ -#define phys_to_machine_mapping(d, gpfn) \ +#define get_mfn_from_pfn(d, gpfn) \ ((d) == dom0 ? gpfn : \ (gpfn <= d->arch.max_pfn ? (d)->arch.pmt[(gpfn)] : \ INVALID_MFN)) @@ -414,7 +414,7 @@ extern unsigned long *mpt_table; machine_to_phys_mapping[(mfn)] #define __gpfn_to_mfn(_d, gpfn) \ - phys_to_machine_mapping((_d), (gpfn)) + get_mfn_from_pfn((_d), (gpfn)) #define __gpfn_invalid(_d, gpfn) \ (__gpfn_to_mfn((_d), (gpfn)) & GPFN_INV_MASK) diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index adab08a3ee..d2e66253cc 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -255,28 +255,31 @@ int check_descriptor(struct desc_struct *d); * contiguous (or near contiguous) physical memory. */ #undef machine_to_phys_mapping -#define machine_to_phys_mapping ((u32 *)RDWR_MPT_VIRT_START) +#define machine_to_phys_mapping ((u32 *)RDWR_MPT_VIRT_START) #define INVALID_M2P_ENTRY (~0U) #define VALID_M2P(_e) (!((_e) & (1U<<31))) #define IS_INVALID_M2P_ENTRY(_e) (!VALID_M2P(_e)) +#define set_pfn_from_mfn(mfn, pfn) (machine_to_phys_mapping[(mfn)] = (pfn)) +#define get_pfn_from_mfn(mfn) (machine_to_phys_mapping[(mfn)]) + /* * The phys_to_machine_mapping is the reversed mapping of MPT for full * virtualization. It is only used by shadow_mode_translate()==true * guests, so we steal the address space that would have normally * been used by the read-only MPT map. */ -#define __phys_to_machine_mapping ((unsigned long *)RO_MPT_VIRT_START) -#define INVALID_MFN (~0UL) -#define VALID_MFN(_mfn) (!((_mfn) & (1U<<31))) +#define phys_to_machine_mapping ((unsigned long *)RO_MPT_VIRT_START) +#define INVALID_MFN (~0UL) +#define VALID_MFN(_mfn) (!((_mfn) & (1U<<31))) -/* Returns the machine physical */ -static inline unsigned long phys_to_machine_mapping(unsigned long pfn) +#define set_mfn_from_pfn(pfn, mfn) (phys_to_machine_mapping[(pfn)] = (mfn)) +static inline unsigned long get_mfn_from_pfn(unsigned long pfn) { unsigned long mfn; l1_pgentry_t pte; - if ( (__copy_from_user(&pte, &__phys_to_machine_mapping[pfn], + if ( (__copy_from_user(&pte, &phys_to_machine_mapping[pfn], sizeof(pte)) == 0) && (l1e_get_flags(pte) & _PAGE_PRESENT) ) mfn = l1e_get_pfn(pte); @@ -285,7 +288,6 @@ static inline unsigned long phys_to_machine_mapping(unsigned long pfn) return mfn; } -#define set_machinetophys(_mfn, _pfn) machine_to_phys_mapping[(_mfn)] = (_pfn) #ifdef MEMORY_GUARD void memguard_init(void); diff --git a/xen/include/asm-x86/shadow.h b/xen/include/asm-x86/shadow.h index fe0bf1c198..15ab87edf1 100644 --- a/xen/include/asm-x86/shadow.h +++ b/xen/include/asm-x86/shadow.h @@ -269,14 +269,14 @@ static inline void shadow_mode_disable(struct domain *d) #define __mfn_to_gpfn(_d, mfn) \ ( (shadow_mode_translate(_d)) \ - ? machine_to_phys_mapping[(mfn)] \ + ? get_pfn_from_mfn(mfn) \ : (mfn) ) #define __gpfn_to_mfn(_d, gpfn) \ ({ \ ASSERT(current->domain == (_d)); \ (shadow_mode_translate(_d)) \ - ? phys_to_machine_mapping(gpfn) \ + ? get_mfn_from_pfn(gpfn) \ : (gpfn); \ }) @@ -461,7 +461,7 @@ static inline int __mark_dirty(struct domain *d, unsigned int mfn) // This wants the nice compact set of PFNs from 0..domain's max, // which __mfn_to_gpfn() only returns for translated domains. // - pfn = machine_to_phys_mapping[mfn]; + pfn = get_pfn_from_mfn(mfn); /* * Values with the MSB set denote MFNs that aren't really part of the @@ -562,7 +562,7 @@ update_hl2e(struct vcpu *v, unsigned long va) old_hl2e = v->arch.hl2_vtable[index]; if ( (l2e_get_flags(gl2e) & _PAGE_PRESENT) && - VALID_MFN(mfn = phys_to_machine_mapping(l2e_get_pfn(gl2e))) ) + VALID_MFN(mfn = get_mfn_from_pfn(l2e_get_pfn(gl2e))) ) new_hl2e = l1e_from_pfn(mfn, __PAGE_HYPERVISOR); else new_hl2e = l1e_empty(); diff --git a/xen/include/asm-x86/shadow_64.h b/xen/include/asm-x86/shadow_64.h index 524d1ef85c..b4af0b3d51 100644 --- a/xen/include/asm-x86/shadow_64.h +++ b/xen/include/asm-x86/shadow_64.h @@ -138,7 +138,7 @@ static inline pgentry_64_t *__entry( return NULL; mfn = entry_get_value(*le_e) >> PAGE_SHIFT; if ((flag & GUEST_ENTRY) && shadow_mode_translate(d)) - mfn = phys_to_machine_mapping(mfn); + mfn = get_mfn_from_pfn(mfn); le_p = (pgentry_64_t *)phys_to_virt(mfn << PAGE_SHIFT); index = table_offset_64(va, (level + i - 1)); le_e = &le_p[index]; @@ -257,7 +257,7 @@ static inline void * __guest_set_l1e( if (unlikely(!(l2e_get_flags_32(gl2e) & _PAGE_PRESENT))) return NULL; - l1mfn = phys_to_machine_mapping( + l1mfn = get_mfn_from_pfn( l2e_get_pfn(gl2e)); l1va = (l1_pgentry_32_t *) @@ -299,7 +299,7 @@ static inline void * __guest_get_l1e( return NULL; - l1mfn = phys_to_machine_mapping( + l1mfn = get_mfn_from_pfn( l2e_get_pfn(gl2e)); l1va = (l1_pgentry_32_t *) phys_to_virt( l1mfn << L1_PAGETABLE_SHIFT); diff --git a/xen/include/asm-x86/vmx_platform.h b/xen/include/asm-x86/vmx_platform.h index 31fb44ae33..ad67545db5 100644 --- a/xen/include/asm-x86/vmx_platform.h +++ b/xen/include/asm-x86/vmx_platform.h @@ -91,6 +91,6 @@ extern int vmx_setup_platform(struct vcpu *, struct cpu_user_regs *); extern void vmx_io_assist(struct vcpu *v); // XXX - think about this -- maybe use bit 30 of the mfn to signify an MMIO frame. -#define mmio_space(gpa) (!VALID_MFN(phys_to_machine_mapping((gpa) >> PAGE_SHIFT))) +#define mmio_space(gpa) (!VALID_MFN(get_mfn_from_pfn((gpa) >> PAGE_SHIFT))) #endif -- 2.30.2